package com.hzy.fivepalace.admin.service;


import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hzy.fivepalace.common.consts.RedisKeyConsts;
import com.hzy.fivepalace.common.express.ExpressService;
import com.hzy.fivepalace.common.notify.NotifyService;
import com.hzy.fivepalace.common.notify.NotifyType;
import com.hzy.fivepalace.common.service.redis.RedisCache;
import com.hzy.fivepalace.common.type.OrderStatusEnums;
import com.hzy.fivepalace.common.type.VipTypeEnums;
import com.hzy.fivepalace.common.util.*;
import com.hzy.fivepalace.db.dao.ex.OrderMapper;
import com.hzy.fivepalace.db.domain.*;
import com.hzy.fivepalace.db.handle.OrderHandler;
import com.hzy.fivepalace.db.handle.OrderOperator;
import com.hzy.fivepalace.db.service.DtsOrderGoodsService;
import com.hzy.fivepalace.db.service.DtsOrderService;
import com.hzy.fivepalace.db.service.DtsUserService;
import com.hzy.fivepalace.db.service.RefundService;
import com.hzy.fivepalace.db.vo.admin.AdminVipByRecordsVo;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;


/**
 * 订单服务
 */
@Service
public class AdminOrderService {

    private static final Logger logger = LoggerFactory.getLogger(AdminOrderService.class);


    @Resource
    private OrderMapper orderMapper;

    @Autowired
    private DtsOrderService orderService;

    @Autowired
    private DtsOrderGoodsService orderGoodsService;

    @Autowired
    private ExpressService expressService;

    @Resource
    private OrderHandler orderHandler;

    @Resource
    private Redisson redisson;

    @Resource
    private DtsUserService userService;

    @Autowired
    private NotifyService notifyService;

    @Resource
    private RedisCache redisCache;

    @Autowired
    private RefundService refundService;

    /**
     * 获取会员开通记录
     * @param page
     * @param size
     * @param userId 用户id(可以查某个用户的)
     * @param vipType 会员类型(可以查某个类型的会员)
     * @param mobile 手机号(可以根据手机号搜索)
     * @param keyWord 关键字(可以匹配用户昵称和手机号)
     * @return
     */
    public TableDataInfo getVipByRecordsList(Integer page, Integer size, Integer userId, Integer vipType,String mobile, String keyWord) {
        if(null!=vipType&&null== VipTypeEnums.getEnum(vipType)){
            return TableDataInfo.errorDataTable("参数【vipType】错误");
        }
        Page p = PageHelper.startPage(page, size);
        List<AdminVipByRecordsVo> list=  orderMapper.getVipByRecordsList(userId,vipType,mobile,keyWord) ;
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
        }
        return TableDataInfo.getDataTable(list, p.getTotal());
    }
    /**
     * 订单列表
     *
     * @param page
     * @param size
     * @param status  状态:为空就查所有,新增-1状态(查售后订单列表)
     * @param phone
     * @param userId
     * @param name
     * @param orderSn
     * @return
     */
    public TableDataInfo getUserOrderList(Integer page, Integer size, Integer status, String phone, Integer userId, String name, String orderSn) {
        //检索状态集合
        List<Short> statusList = new ArrayList<>();
        String orderByStr="add_time desc";
        if (null != status && status.intValue() != -1) {
            OrderStatusEnums orderStatusEnums = OrderStatusEnums.getEnum(status);
            if (null == orderStatusEnums) {
                return TableDataInfo.errorDataTable("查询状态错误");
            }
            if (orderStatusEnums.getType() == OrderStatusEnums.TYPE4.getType()) {//如果查询的是已完成，那么查询状态就是待评价和已完成的
                statusList.add((short) OrderStatusEnums.TYPE4.getType());
                statusList.add((short) OrderStatusEnums.TYPE3.getType());
            } else {
                statusList.add(status.shortValue());
            }
        } else {
            if (null != status&&status.intValue() == -1) {
                statusList.add((short) OrderStatusEnums.TYPE5.getType());//已退款，直接退款的
                statusList.add((short) OrderStatusEnums.TYPE7.getType());//退款处理中
                statusList.add((short) OrderStatusEnums.TYPE8.getType());//售后审核中
                statusList.add((short) OrderStatusEnums.TYPE10.getType());//售后完成-已退款
                statusList.add((short) OrderStatusEnums.TYPE11.getType());//待上传物流信息
                statusList.add((short) OrderStatusEnums.TYPE12.getType());//待商家收货
                orderByStr="update_time desc,add_time desc";
            }
        }
        List<Map<String, Object>> orderVoList = new ArrayList<>();
        Page p = PageHelper.startPage(page, size, true);
        List<DtsOrderWithBLOBs> list = orderService.getOrderList(statusList, phone, userId, name, orderSn,orderByStr);
        list.forEach(item -> {
            DtsOrder order = JSONObject.parseObject(JSON.toJSONString(item), DtsOrder.class);
            Map<String, Object> orderVo = ObjectUtils.convertToMap(order);
            //支付方式
            orderVo.put("payName", null);

            //售后描述,前端判断该字段不为空就可以显示
            orderVo.put("afterSaleDescribe", item.getAfterSaleDescribe());

            //售后拒绝原因
            orderVo.put("afterSaleRefusedReason", item.getAfterSaleRefusedReason());

            if (order.getOrderStatus().intValue() != OrderStatusEnums.TYPE0.getType() && order.getOrderStatus().intValue() != OrderStatusEnums.TYPE6.getType()) {//已支付拼接支付方式
                if (order.getOrderPrice().compareTo(new BigDecimal("0.00")) <= 0) {//订单金额小于等于0就为免费订单
                    //支付方式
                    orderVo.put("payName", "免费订单");
                } else {
                    //支付方式
                    orderVo.put("payName", "微信支付");
                }
            }
            //订单状态名称处理
            OrderStatusEnums orderStatusEnums = OrderStatusEnums.getEnum(order.getOrderStatus().intValue());
            if (null != orderStatusEnums && orderStatusEnums.getType() == OrderStatusEnums.TYPE3.getType()) {//如果订单是待评价状态，就拼接一个状态名字
                orderVo.put("orderStatusName", "已完成,待用户评价");
            }
            if (null != orderStatusEnums && orderStatusEnums.getType() == OrderStatusEnums.TYPE6.getType()) {//如果订单是待评价状态，就拼接一个用户取消,因为这块查到的已取消肯定是用户取消的
                orderVo.put("orderStatusName", "用户取消");
            } else {
                orderVo.put("orderStatusName", null == orderStatusEnums ? "未知状态" : orderStatusEnums.getName());
            }
            //查询订单商品信息
            List<DtsOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
            orderVo.put("goodsList", orderGoodsList);

            //pc端订单按钮操作
            OrderOperator orderOperator = orderHandler.build(order);
            //订单发货按钮操作:待发货状态才能发货
            orderVo.put("deliveryOperator", (OrderStatusEnums.TYPE1.getType() == order.getOrderStatus().intValue() && order.getFreightType().intValue() == 0));
            //是否可以查看订单物流
            orderVo.put("showLogistics", orderOperator.isShowLogistics());
            //是否可以查看退货物流信息
            orderVo.put("showReturnLogistics", orderOperator.isShowReturnLogistics());
            //是否可以进行售后审核
            orderVo.put("applyAfterSaleOperator", (OrderStatusEnums.TYPE8.getType() == order.getOrderStatus().intValue()));
            //是否可以对订单进行单独退款(也就是和小程序端一样单独极速退款)
            orderVo.put("refundOperator", orderOperator.isRefund());
            //售后-退款操作按钮，只有当前订单状态为12(待商家收货的时候)才可以操作收获退款，因为售后审核的时候处置方式可能是需要退货退款，用户把货退来了，后台才能操作退款
            //这里前端的按钮名称可以设置为：确认收货并退款
            orderVo.put("afterSaleRefundOperator", (OrderStatusEnums.TYPE12.getType() == order.getOrderStatus().intValue()));

            //获取下单用户信息
            orderVo.put("userInfo", userService.getUserNickNameAndPhoneAndAvatar(order.getUserId()));
            orderVoList.add(orderVo);
        });

        return TableDataInfo.getDataTable(orderVoList, p.getTotal());
    }


    /**
     * 订单详情
     *
     * @param orderId
     * @return
     */
    public Object orderDetails(Integer orderId) {
        // 订单信息
        DtsOrderWithBLOBs orderWithBLOBs = orderService.findById(orderId);
        if (null == orderWithBLOBs||orderWithBLOBs.getIsByVip()) {
            return ResponseUtil.fail("订单不存在");
        }
        DtsOrder order = JSONObject.parseObject(JSON.toJSONString(orderWithBLOBs), DtsOrder.class);

        Map<String, Object> orderVo = ObjectUtils.convertToMap(order);

        //支付方式
        orderVo.put("payName", null);

        //售后描述,前端判断该字段不为空就可以显示
        orderVo.put("afterSaleDescribe", orderWithBLOBs.getAfterSaleDescribe());

        //售后拒绝原因
        orderVo.put("afterSaleRefusedReason", orderWithBLOBs.getAfterSaleRefusedReason());

        if (order.getOrderStatus().intValue() != OrderStatusEnums.TYPE0.getType() && order.getOrderStatus().intValue() != OrderStatusEnums.TYPE6.getType()) {//已支付拼接支付方式
            if (order.getOrderPrice().compareTo(new BigDecimal("0.00")) <= 0) {//订单金额小于等于0就为免费订单
                //支付方式
                orderVo.put("payName", "免费订单");
            } else {
                //支付方式
                orderVo.put("payName", "微信支付");
            }
        }
        //订单状态名称处理
        OrderStatusEnums orderStatusEnums = OrderStatusEnums.getEnum(order.getOrderStatus().intValue());
        if (null != orderStatusEnums && orderStatusEnums.getType() == OrderStatusEnums.TYPE3.getType()) {//如果订单是待评价状态，就拼接一个状态名字
            orderVo.put("orderStatusName", "已完成,待用户评价");
        }
        if (null != orderStatusEnums && orderStatusEnums.getType() == OrderStatusEnums.TYPE6.getType()) {//如果订单是待评价状态，就拼接一个用户取消,因为这块查到的已取消肯定是用户取消的
            orderVo.put("orderStatusName", "用户取消");
        } else {
            orderVo.put("orderStatusName", null == orderStatusEnums ? "未知状态" : orderStatusEnums.getName());
        }
        //查询订单商品信息
        List<DtsOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
        orderVo.put("goodsList", orderGoodsList);

        //获取下单用户信息
        orderVo.put("userInfo", userService.getUserNickNameAndPhoneAndAvatar(order.getUserId()));

        //pc端订单按钮操作
        OrderOperator orderOperator = orderHandler.build(order);
        //订单发货按钮操作:待发货状态才能发货
        orderVo.put("deliveryOperator", (OrderStatusEnums.TYPE1.getType() == order.getOrderStatus().intValue() && order.getFreightType().intValue() == 0));
        //是否可以查看订单物流
        orderVo.put("showLogistics", orderOperator.isShowLogistics());
        //是否可以查看退货物流信息
        orderVo.put("showReturnLogistics", orderOperator.isShowReturnLogistics());
        //是否可以进行售后审核
        orderVo.put("applyAfterSaleOperator", (OrderStatusEnums.TYPE8.getType() == order.getOrderStatus().intValue()));
        //是否可以对订单进行单独退款(也就是和小程序端一样单独极速退款)
        orderVo.put("refundOperator", orderOperator.isRefund());
        //售后-退款操作按钮，只有当前订单状态为12(待商家收货的时候)才可以操作收获退款，因为售后审核的时候处置方式可能是需要退货退款，用户把货退来了，后台才能操作退款
        //这里前端的按钮名称可以设置为：确认收货并退款
        orderVo.put("afterSaleRefundOperator", (OrderStatusEnums.TYPE12.getType() == order.getOrderStatus().intValue()));

        return ResponseUtil.ok(orderVo);
    }

    /**
     * 查看物流
     *
     * @param orderId
     * @return
     */
    public Object queryLogistics(Integer orderId) {
        // 订单信息
        DtsOrder order = orderService.findById(orderId);
        if (null == order||order.getIsByVip()) {
            return ResponseUtil.fail("获取物流信息失败,订单不存在");
        }
        //订单状态校验是否可以操作
        OrderOperator operator = orderHandler.build(order);
        if (!operator.isShowLogistics()) {
            return ResponseUtil.fail("获取物流信息失败,订单状态不支持查看");
        }
        return expressService.getExpressInfo(order.getShipChannel(), order.getShipSn(),order.getMobile());
    }

    /**
     * 查看退货物流
     *
     * @param orderId
     * @return
     */
    public Object queryReturnLogistics(Integer orderId) {
        // 订单信息
        DtsOrder order = orderService.findById(orderId);
        if (null == order||order.getIsByVip()) {
            return ResponseUtil.fail("获取物流信息失败,订单不存在");
        }
        //订单状态校验是否可以操作
        OrderOperator operator = orderHandler.build(order);
        if (!operator.isShowReturnLogistics()) {
            return ResponseUtil.fail("获取物流信息失败,订单状态不支持查看");
        }
        return expressService.getExpressInfo(order.getReturnShipChannel(), order.getReturnShipSn(),order.getMobile());
    }

    /**
     * 获取所有快递公司
     *
     * @return
     */
    public Object getAllShipChannel() {

        return ResponseUtil.ok(expressService.getAllShipChannel());
    }

    /**
     * 订单发货
     *
     * @param orderId
     * @param shipCode
     * @param shipSn
     * @return
     */
    public Object delivery(Integer orderId, String shipCode, String shipSn) {
        RLock lock = redisson.getLock("admin_order_delivery" + orderId);
        if (lock.isLocked()) {
            return ResponseUtil.frequent("其他管理人员操作中,请稍后再试");
        }
        lock.lock(30, TimeUnit.SECONDS);

        if (StringUtils.isBlank(shipCode)) {
            lock.unlock();
            return ResponseUtil.fail("未选择快递公司");
        }
        if (StringUtils.isBlank(shipSn)) {
            lock.unlock();
            return ResponseUtil.fail("快递单号不能为空");
        }
        //校验快递公司
        String vendorName = expressService.getVendorName(shipCode);
        if (StringUtils.isBlank(vendorName)) {
            lock.unlock();
            return ResponseUtil.fail("不受支持的快递公司");
        }

        // 订单信息
        DtsOrder order = orderService.findById(orderId);
        if (null == order||order.getIsByVip()) {
            lock.unlock();
            return ResponseUtil.fail("订单不存在");
        }
        //订单状态校验是否可以操作
        if (order.getFreightType().intValue() != 0) {
            lock.unlock();
            return ResponseUtil.fail("自提订单无法发货");
        }
        if (OrderStatusEnums.TYPE1.getType() != order.getOrderStatus().intValue()) {
            lock.unlock();
            return ResponseUtil.fail("订单状态无法发货");
        }

        //插入自动收货缓存
        redisCache.setCacheObject(RedisKeyConsts.AUTOMATIC_RECEIPT_GOODS_KEY + order.getOrderSn(), order.getOrderSn(), 15, TimeUnit.DAYS);
        DtsOrderWithBLOBs orderUpd = new DtsOrderWithBLOBs();
        orderUpd.setId(orderId);
        orderUpd.setShipSn(shipSn);
        orderUpd.setShipChannel(shipCode);
        //订单状态改为待收货
        orderUpd.setOrderStatus((short) OrderStatusEnums.TYPE2.getType());
        orderUpd.setShipTime(LocalDateTime.now());
        orderUpd.setUpdateTime(LocalDateTime.now());
        orderService.updateById(orderUpd);
        DtsUser user = userService.findById(order.getUserId());
        String goodsName = orderService.getGoodsNameByOrderId(orderId);
        if (null != user) {
            //给用户推送发货提醒
            notifyService.notifyWxTemplate(user.getWeixinOpenid(), NotifyType.SHIP, new String[]{order.getOrderSn(), vendorName, shipSn, goodsName}, "/pages/dingdanxiangqing/dingdanxiangqing?orderId=" + orderId);
        }
        lock.unlock();
        return ResponseUtil.ok("发货成功", null);
    }

    /**
     * 订单单独退款
     *
     * @param orderId
     * @param refundDesc
     * @return
     */
    public Object orderRefund(Integer orderId, String refundDesc) {
        if (null == orderId || orderId.intValue() < 1) {
            return ResponseUtil.fail("参数【orderId】为空");
        }

        RLock lock = redisson.getLock("admin_orderRefund_" + orderId);
        if (lock.isLocked()) {
            return ResponseUtil.frequent("其他管理人员操作中,请稍后再试");
        }
        lock.lock(30, TimeUnit.SECONDS);


        if (StringUtils.isBlank(refundDesc)) {
            lock.unlock();
            return ResponseUtil.fail("请填写退款原因");
        }

        // 订单信息
        DtsOrderWithBLOBs orderWithBLOBs = orderService.findById(orderId);
        if (null == orderWithBLOBs||orderWithBLOBs.getIsByVip()) {
            lock.unlock();
            return ResponseUtil.fail("订单不存在");
        }
        //订单状态校验是否可以操作
        OrderOperator operator = orderHandler.build(orderWithBLOBs);
        if (!operator.isRefund()) {
            lock.unlock();
            return ResponseUtil.fail("当前订单状态不支持退款");
        }
        Object result = refundService.initiateWechatRefund(orderWithBLOBs, refundDesc + ",本单由商家操作退款", true);
        lock.unlock();
        return result;
    }

    /**
     * 售后完成并退款
     * 解释：
     * 只有当前订单状态为12(待商家收货的时候)才可以操作收获退款，因为售后审核的时候处置方式可能是需要退货退款，用户把货退来了，后台才能操作退款
     *
     * @param orderId
     * @return
     */
    public Object afterSaleRefund(Integer orderId) {
        if (null == orderId || orderId.intValue() < 1) {
            return ResponseUtil.fail("参数【orderId】为空");
        }

        RLock lock = redisson.getLock("admin_afterSaleRefund_" + orderId);
        if (lock.isLocked()) {
            return ResponseUtil.frequent("其他管理人员操作中,请稍后再试");
        }
        lock.lock(30, TimeUnit.SECONDS);


        // 订单信息
        DtsOrderWithBLOBs orderWithBLOBs = orderService.findById(orderId);
        if (null == orderWithBLOBs||orderWithBLOBs.getIsByVip()) {
            lock.unlock();
            return ResponseUtil.fail("订单不存在");
        }
        //订单状态校验是否可以操作
        if (OrderStatusEnums.TYPE12.getType() != orderWithBLOBs.getOrderStatus().intValue()) {
            lock.unlock();
            return ResponseUtil.fail("当前订单状态不支持退款");
        }

        Object result = refundService.initiateWechatRefund(orderWithBLOBs, "本次售后完成,由商家操作退款", false);
        lock.unlock();
        return result;
    }

    /**
     * 售后审核
     *
     * @param orderId
     * @param disposeType
     * @param reason
     * @return
     */
    public Object applyAfterSale(Integer orderId, Integer disposeType, String reason) {
        if (null == orderId || orderId.intValue() < 1) {
            return ResponseUtil.fail("参数【orderId】为空");
        }
        RLock lock = redisson.getLock("admin_applyAfterSale_" + orderId);
        if (lock.isLocked()) {
            return ResponseUtil.frequent("其他管理人员操作中,请稍后再试");
        }
        lock.lock(30, TimeUnit.SECONDS);
        //入参校验
        if (null == disposeType) {
            lock.unlock();
            return ResponseUtil.fail("请选择处理方式");
        }
        if (disposeType.intValue() != 0 && disposeType.intValue() != 1 && disposeType.intValue() != 2) {
            lock.unlock();
            return ResponseUtil.fail("参数【disposeType】错误");
        }
        if (disposeType.intValue() == 0 && StringUtils.isBlank(reason)) {
            lock.unlock();
            return ResponseUtil.fail("请填写拒绝原因");
        }
        // 订单信息
        DtsOrderWithBLOBs orderWithBLOBs = orderService.findById(orderId);
        if (null == orderWithBLOBs||orderWithBLOBs.getIsByVip()) {
            lock.unlock();
            return ResponseUtil.fail("订单不存在");
        }
        //订单状态校验是否可以操作
        if (OrderStatusEnums.TYPE8.getType() != orderWithBLOBs.getOrderStatus().intValue()) {
            lock.unlock();
            return ResponseUtil.fail("当前订单状态不支持售后审核");
        }

        if (disposeType.intValue() == 0) {//拒绝
            //判断计算出未申请售后时的订单状态
            Integer oldOrderStatus = null;
            if (orderWithBLOBs.getComments().intValue() > 0 && null == orderWithBLOBs.getConfirmTime()) {//如果待评价订单商品数量大于0并且确认收货时间为空，那么一定是待收货状态
                oldOrderStatus = OrderStatusEnums.TYPE2.getType();
            } else if (orderWithBLOBs.getComments().intValue() > 0 && null != orderWithBLOBs.getConfirmTime()) {//如果待评价订单商品数量大于0并且确认收货时间不为空，那么一定是待评价状态
                oldOrderStatus = OrderStatusEnums.TYPE3.getType();
            } else if (orderWithBLOBs.getComments().intValue() < 1 && null != orderWithBLOBs.getConfirmTime()) {//如果待评价订单商品数量小于1并且确认收货时间不为空，那么一定是已完成状态
                oldOrderStatus = OrderStatusEnums.TYPE4.getType();
            } else {
                lock.unlock();
                return ResponseUtil.fail("计算未申请售后时的订单状态出错");
            }

            DtsOrderWithBLOBs orderUpd = new DtsOrderWithBLOBs();
            orderUpd.setId(orderId);
            //修改订单状态为未申请售后时的订单状态
            orderUpd.setOrderStatus(oldOrderStatus.shortValue());
            //商家售后处理时间
            orderUpd.setAfterSaleDisposeTime(LocalDateTime.now());
            //拒绝原因
            orderUpd.setAfterSaleRefusedReason(reason);
            orderUpd.setUpdateTime(LocalDateTime.now());
            orderService.updateById(orderUpd);
            try {
                DtsUser user = userService.findById(orderWithBLOBs.getUserId());
                if (null != user) {
                    //给用户推送售后状态通知
                    notifyService.notifyWxTemplate(user.getWeixinOpenid(), NotifyType.AFTERSALE, new String[]{"申请售后","售后审核未通过,点击查看详情"}, "/pages/dingdanxiangqing/dingdanxiangqing?orderId=" + orderWithBLOBs.getId());
                }
            }catch (Exception e){

            }
            lock.unlock();
            return ResponseUtil.ok("操作成功",null);
        } else if (disposeType.intValue() == 1) {//仅退款
            LocalDateTime dateTime=LocalDateTime.now();
            Map<String,Object> result = (Map) refundService.initiateWechatRefund(orderWithBLOBs, "本次售后完成,由商家操作退款", false);
            if(MapUtils.getIntValue(result,"code")==ResponseUtil.SUCCESS_CODE){
                DtsOrderWithBLOBs orderUpd = new DtsOrderWithBLOBs();
                orderUpd.setId(orderId);
                //商家售后处理时间
                orderUpd.setAfterSaleDisposeTime(dateTime);
                //售后类型为1仅退款
                orderUpd.setApplyAfterSaleType(1);
                orderService.updateById(orderUpd);
            }
            lock.unlock();
            return result;
        } else{//退货退款
            DtsOrderWithBLOBs orderUpd = new DtsOrderWithBLOBs();
            orderUpd.setId(orderId);
            //修改订单状态为待用户上传退货物流信息
            orderUpd.setOrderStatus((short)OrderStatusEnums.TYPE11.getType());
            //商家售后处理时间
            orderUpd.setAfterSaleDisposeTime(LocalDateTime.now());
            //拒绝原因
            orderUpd.setAfterSaleRefusedReason("");
            orderUpd.setUpdateTime(LocalDateTime.now());
            //售后类型为2退货退款
            orderUpd.setApplyAfterSaleType(2);
            orderService.updateById(orderUpd);
            try {
                DtsUser user = userService.findById(orderWithBLOBs.getUserId());
                if (null != user) {
                    //给用户推送售后状态通知
                    notifyService.notifyWxTemplate(user.getWeixinOpenid(), NotifyType.AFTERSALE, new String[]{"退货退款","审核通过,待上传退货物流信息"}, "/pages/dingdanxiangqing/dingdanxiangqing?orderId=" + orderWithBLOBs.getId());
                }
            }catch (Exception e){

            }
            lock.unlock();
            return ResponseUtil.ok("操作成功",null);
        }
    }
}
